package com.gofaraway.service.shipment.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gofaraway.common.domin.PagingResponse;
import com.gofaraway.common.util.bean.PojoConvert;
import com.gofaraway.dao.mysql.dto.ShipmentSearchRequestDTO;
import com.gofaraway.dao.mysql.trunk.entity.StoShipment;
import com.gofaraway.dao.mysql.trunk.service.IStoShipmentService;
import com.gofaraway.service.facade.request.ShipmentPageSearchRequest;
import com.gofaraway.service.facade.request.ShipmentSearchRequest;
import com.gofaraway.service.facade.response.ShipmentResponse;
import com.gofaraway.service.shipment.ShipmentManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ChenPeng
 * @Date 2024/1/18 16:33
 */
@Service
@Slf4j
public class ShipmentManageServiceImpl implements ShipmentManageService {

    @Autowired
    private IStoShipmentService iStoShipmentService;

    @Override
    public List<ShipmentResponse> shipmentSearch(ShipmentSearchRequest request) {
        LambdaQueryWrapper<StoShipment> wrapper = Wrappers.<StoShipment>lambdaQuery()
                .in(StoShipment::getShipmentNo, request.getShipmentNos());
        List<StoShipment> list = iStoShipmentService.list(wrapper);

        List<ShipmentResponse> shipmentResponses = PojoConvert.beanListConvert(list, ShipmentResponse::new);
        log.info("shipmentSearch:{}", shipmentResponses);
        return shipmentResponses;
    }

    @Override
    public PagingResponse<ShipmentResponse> pageQuery(ShipmentPageSearchRequest queryRequest) {
        ShipmentSearchRequestDTO dto = PojoConvert.copyProperties(queryRequest, ShipmentSearchRequestDTO::new);
        IPage<StoShipment> shipmentPage = iStoShipmentService.pageQuery(dto);
        return PagingResponse.pageConvert(shipmentPage, ShipmentResponse::new);
    }
}
